package com.example.apione.model;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.apione.dao.ApiInfoDao;
import com.example.apione.entity.ApiInfo;
import com.example.apione.utils.ResponseResult;
import java.util.List;


/**
 * @author 尘落
 * @date 2023/2/23
 */
public class getApimodel {
    public static ResponseResult<List<ApiInfo>> getall(ApiInfoDao apiInfoDao){
        QueryWrapper<ApiInfo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        List<ApiInfo> allApiList = apiInfoDao.selectList(wrapper);
        return ResponseResult.ok(allApiList);
    }
    public static ResponseResult<List<ApiInfo>> searchapi(ApiInfoDao apiInfoDao,String param){
        QueryWrapper<ApiInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",param);
        List<ApiInfo> searchapilist = apiInfoDao.selectList(queryWrapper);
        return ResponseResult.ok(searchapilist);
    }
    public static ResponseResult<ApiInfo> oneapi(ApiInfoDao apiInfoDao,String param){
        QueryWrapper<ApiInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("doc",param);
        ApiInfo searchapilist = apiInfoDao.selectOne(queryWrapper);
        return ResponseResult.ok(searchapilist);
    }

    public static String onedoc(ApiInfoDao apiInfoDao,String param){
        QueryWrapper<ApiInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("doc",param);
        ApiInfo searchapilist = apiInfoDao.selectOne(queryWrapper);
        String str=searchapilist.getExampleurl();
        return str;
    }
    public static String oneapidoc(ApiInfoDao apiInfoDao,String param){
        QueryWrapper<ApiInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("doc",param);
        ApiInfo searchapilist = apiInfoDao.selectOne(queryWrapper);
        UpdateWrapper<ApiInfo> updateWrapper=new UpdateWrapper<>();
        Integer count = searchapilist.getCount();
        count++;
        updateWrapper.eq("doc",param);
        updateWrapper.set("count",count);
        apiInfoDao.update(null,updateWrapper);
        return searchapilist.getPath();
    }
}
